<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<button>stop setTimeout</button>
<script>
  var btn = document.querySelector('button');
  var callback = function () {
    console.log('callback 调用');
  };

  var timer = window.setTimeout(callback, 2000);
  btn.addEventListener('click', function () {
    clearTimeout(timer);
  })
</script>
</body>
</html>